package com.auto.signup.dao;

import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * 微信token redis存储
 * 
 * @author gaomingzheng
 *
 */
@Repository
public class WeixinTokenDao implements IWeixinTokenDao {

	Map<String,Object> cacheMap = new HashMap<>();

	public static String TOKEN_REDIS_KEY_PREFIX = "system:token-";

	@Override
	public void save(String key, String token, Long expires) {
		cacheMap.put(getKey(key), token);
	}

	@Override
	public String getToken(String key) {
		Object object = cacheMap.get(getKey(key));
		return object == null ? "" : Objects.toString(object);
	}

	private String getKey(String key) {
		return TOKEN_REDIS_KEY_PREFIX + key;
	}

}
